#include <catch2/catch.hpp>

#include "solution.hpp"

using namespace solution_099;

TEST_CASE("99. Recover Binary Search Tree", "[099]") {

std::array n{ TreeNode(0), TreeNode(1), TreeNode(2), TreeNode(3), TreeNode(4) };

SECTION("example 1") {
    n[1].left  = &n[3];
    n[3].right = &n[2];
    Solution().recoverTree(&n[1]);

    CHECK(n[1].val == 3);
    CHECK(n[1].left->val == 1);
    CHECK(n[1].left->right->val == 2);
}

SECTION("example 2") {
    n[2].left  = &n[3];
    n[2].right = &n[1];
    Solution().recoverTree(&n[2]);

    CHECK(n[2].val == 2);
    CHECK(n[2].left->val == 1);
    CHECK(n[2].right->val == 3);
}

SECTION("example 3") {
    n[3].left  = &n[1];
    n[3].right = &n[4];
    n[4].left  = &n[2];
    Solution().recoverTree(&n[3]);

    CHECK(n[3].val == 2);
    CHECK(n[3].left->val == 1);
    CHECK(n[3].right->val == 4);
    CHECK(n[3].right->left->val == 3);
}

}
